<%
/**
 *      地址本js
 *      含是否多选的参数
 *
 *  $Author: amon_lei $
 *  $Date: 2005/01/01 13:59:13 $
 *  $Revision: 1.3 $ 
 *  created in 2004-12-12
 *
 *
 */
%>
<script>

  function makeSure()
  {
        var selecteditermids = new Array();
        var selecteditermnames = new Array();
        var selecteditermtypes = new Array();
        for(var i = 0;i < selecteditermid.options.length;i++)
        {
                selecteditermids[i] = selecteditermid.options(i).value;
                selecteditermnames[i] = selecteditermname.options(i).value; 
                selecteditermtypes[i] = selecteditermtype.options(i).value;
        }
        opener.setValue(selecteditermids,selecteditermnames,selecteditermtypes);
         window.close();
  }

  function cancel()
  {
    window.close();
  }

  /**
   *  全选
   */
  function allSelected()
  {
     <%
          /* 是否多选 */         
          if(!isMultSelected)
          {  
           %>
             if(selecteditermid.options.length !=0 )
             {
               alert("当前操作只可选择一项");
                   return;
             }                   
           <%
      }
         %>   
        var Nodes = treeId.allSelected();
        for(var i = 0; i < Nodes.length; i++)
        {
          //alert(Nodes[i].NodeID+""+Nodes[i].sText+""+Nodes[i].NodeType);
          //alert(Nodes.length);
          this.setValue(Nodes[i].NodeID,Nodes[i].sText,Nodes[i].NodeType);
        }
  }

  function setValue(itermid,itermname,itermtype)
  {   
     <%
          /* 是否多选 */         
          if(!isMultSelected)
          {  
           %>
                 if(selecteditermid.options.length !=0 )
                 {
               alert("当前操作只可选择一项");
                   return;
             }                   
           <%
      }
         %>
     for(var i = 0;i < selecteditermid.options.length;i++)
         {
           if(selecteditermid.options(i).value==itermid)
           {
             alert(itermname + "已选");
                 return;
           }
         }
        addOption(selecteditermid,itermid,itermname);
        addOption(selecteditermname,itermname,itermname);
        addOption(selecteditermtype,itermtype,itermtype);
  }

  /**
   * 删除
   */
  function del()
  {
        SYC_Selected();
        delOption(selecteditermid);
        delOption(selecteditermname);
        delOption(selecteditermtype); 
  }

  /**
   * 全删
   */
  function delAll()
  {
        /* 全选 */
        selectAllOptions(selecteditermid);
        selectAllOptions(selecteditermname);
        selectAllOptions(selecteditermtype);
        /* 全删 */
        delOption(selecteditermid);
        delOption(selecteditermname);
        delOption(selecteditermtype);
  }
   
  /**
   *  添加Option
   */
   function addOption(container,value,text)
   {
     var oOption = document.createElement("OPTION");                
     oOption.text = text;
         oOption.value = value;
         container.add(oOption);                
   }

  /**
   *  删除Option
   */
   function delOption(container)
   {
     for(var i =0;i<container.options.length;i++)
         {
           if (container.options(i).selected==true)
                 container.options.remove(i--);
         }
   }

   /**
    * option全选
        */
  function selectAllOptions(container)
  {
     for(var i =0;i<container.options.length;i++)
         {
       container.options(i).selected=true;
         }  
  }

  /**
   * 同步select
   */
   function SYC_Selected()
   {
     for(var i =0;i<selecteditermid.options.length;i++)
         {
               var temp = selecteditermid.options(i).selected ;
               selecteditermname.options(i).selected = temp;
               selecteditermtype.options(i).selected = temp;                        
         }  
   }

   /**
    * 不同的地址本重定向
    * 
    */
    function AlistRederict(action,AlistType)
    {
        RedirectForm.action = action;
        RedirectForm.ALType.value = AlistType;
        RedirectForm.submit();
    }
</script>
